﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;

namespace HybridLab.Workflow.Activities.Info
{
	[Serializable]
	public sealed class HybridLabHostCredentials : ICredentials
	{
		public string DomainName { get; set; }
		public string UserName { get; set; }
		public string Password { get; set; }

		public string FullUserName
		{
			get
			{
				if (string.IsNullOrEmpty(DomainName))
				{
					return UserName;
				}
				return string.Format("{0}\\{1}", DomainName, UserName);
			}
		}

		public HybridLabHostCredentials()
			: this(null, null, null)
		{
		}

		public HybridLabHostCredentials(string domainName, string userName, string password)
		{
			DomainName = domainName;
			UserName = userName;
			Password = password;
		}

		public NetworkCredential GetCredential(Uri uri, string authType)
		{
			return new NetworkCredential(UserName, Password, DomainName);
		}

		public override int GetHashCode()
		{
			return base.GetHashCode();
		}

		public override bool Equals(object obj)
		{
			var otherCred = obj as HybridLabHostCredentials;
			return DomainName == otherCred.DomainName && UserName == otherCred.UserName && Password == otherCred.Password;
		}
	}
}
